// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/testing/gtest_utils.h>
#include <pollux/functions/sparksql/tests/SparkFunctionBaseTest.h>

namespace kumo::pollux::functions::sparksql::test {
namespace {

class MonotonicallyIncreasingIdTest : public SparkFunctionBaseTest {
 protected:
  void testMonotonicallyIncreasingId(
      int32_t partitionId,
      int32_t vectorSize,
      const std::vector<int64_t>& expected) {
    setSparkPartitionId(partitionId);
    auto result = evaluate(
        "monotonically_increasing_id()", make_row_vector(ROW({}), vectorSize));
    ASSERT_FALSE(result->is_constant_encoding());
    pollux::test::assertEqualVectors(
        {make_flat_vector<int64_t>(expected)}, result);
  }
};

TEST_F(MonotonicallyIncreasingIdTest, basic) {
  testMonotonicallyIncreasingId(0, 1, {0});
  testMonotonicallyIncreasingId(2, 2, {17179869184, 17179869185});
  testMonotonicallyIncreasingId(5, 3, {42949672960, 42949672961, 42949672962});
  testMonotonicallyIncreasingId(
      100, 4, {858993459200, 858993459201, 858993459202, 858993459203});
}

} // namespace
} // namespace kumo::pollux::functions::sparksql::test
